﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Reflection;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DevExpress.Xpf.Docking;
using DevExpress.Xpf.Editors.Settings;
using DevExpress.Xpf.Grid;
using DevExpress.Xpf.Grid.LookUp;
using GenericGridControl.Annotations;
using GenericGridControl.Model;
using Modularity;
using Newtonsoft.Json;
using OpenLS.Spreadsheet;
using OpenLS.Spreadsheet.Formats;
using OpenLS.Spreadsheet.Formats.JsonStructures;
using QuantumWorkspace.SessionManager;
using Enumerable = OpenLS.Spreadsheet.Enumerable;
using TableColumn = System.Windows.Documents.TableColumn;

namespace GenericGridControl
{
    /// <summary>
    /// Interaction logic for UserControl1.xaml
    /// </summary>
    public partial class BigDataTableControl : LayoutPanel
    {

        private string _tableName;
        private JsonDataTableFormat _JsonTableStructure;

        private ModuleViewModel<StandardBigDataModule> _bigDataTableViewModel;

        public BigDataTableControl()
        {
            InitializeComponent();
            _bigDataTableViewModel = new ModuleViewModel<StandardBigDataModule>();
            _bigDataTableViewModel.CurrentDataModule.CurrentGridControl = this.dynamicTableGrid;
            this.DataContext = _bigDataTableViewModel;
        }

        public Workbook CurrentWorkbook
        {
            set { this._bigDataTableViewModel.CurrentDataModule.CurrentWorkbook = value; }
        }

        public void DefineTableJsonFormat(JsonDataTableFormat structure)
        {
            _JsonTableStructure = structure;
            _bigDataTableViewModel.CurrentDataModule.DefineTableJsonFormat(structure);
        }


        void AddNewRowButton_Click(object sender, RoutedEventArgs e)
        {
            var newRowItem = CodeSession.Instance.GetNewRowItem(_JsonTableStructure);
            _bigDataTableViewModel.CurrentDataModule.DynamicGridSource.Add(newRowItem);
        }

   
        private void CopyButton_Click(object sender, RoutedEventArgs e)
        {
            _bigDataTableViewModel.CurrentDataModule.CopyToSpreadsheet();
        }
    }
}
